package com.project.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;

@RestController
@RequestMapping("user")
public class UserController {
    @RequestMapping("login")
    public String login(String userName, String pwd, HttpServletRequest req) {
        if ("java".equals(userName) && "123".equals(pwd)) {
            req.getSession().setAttribute("loginUser", userName);
            return "ok";
        }
        return "no";
    }

    @RequestMapping("add")
    public String add(String userName, @RequestParam("face") MultipartFile mf) throws IOException {
//        得到客户端上传文件的文件名
        String fileName = mf.getOriginalFilename();
        mf.transferTo(new File("/Users/cengyunke/Desktop/整理/j187web-master/interceptor/src/main/resources/static/userface/" + fileName));
        return "ok";
    }
}
